﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;

namespace gMailSender
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SmtpClient client = new SmtpClient();
            client.Port = 25;
            client.Host = "184.107.177.146";
            client.EnableSsl = false;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;

            client.Credentials = new System.Net.NetworkCredential("vongkol@khschools.com", "KhmerCamb0dia");
            string htmlSms = "<h4 style='color:red'>Notification From Meshtech</h4>";
            htmlSms += "<p style='color:blue'>There is a tool turn off! See the details below.</p>";
            MailMessage mm = new MailMessage("vongkol@khschools.com", "hengvongkol@gmail.com", "test", htmlSms);
            mm.IsBodyHtml = true;
            mm.BodyEncoding = UTF8Encoding.UTF8;
            mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;

            try
            {
                client.Send(mm);
                MessageBox.Show("Send is OK");
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bool State = false;
            string StartTime = "11:30:00 AM";
            string EndTime = "2:00:00 AM";
            DateTime t1 = Convert.ToDateTime(StartTime);
            DateTime t2 = Convert.ToDateTime(EndTime);
            DateTime t = DateTime.Now.ToLocalTime();
            // if current time is AM
            if(t.ToString("tt")=="AM")
            {
                // if t1 and t2 are AM
                if(t1.ToString("tt")=="AM" && t2.ToString("tt")=="AM")
                {
                    // if t1 and t2 are in the same day
                    if(t1.Ticks<t2.Ticks)
                    {
                        // compare t between t1 and t2
                        if(t.Ticks>=t1.Ticks && t.Ticks<=t2.Ticks)
                        {
                            State = true;
                        }
                        else
                        {
                            State = false;
                        }
                    }
                    // if t1 is the next day
                    else
                    {
                        // compare t between t1 and t2
                        if(t.Ticks>=t1.Ticks && t.Ticks<=t2.AddDays(1).Ticks)
                        {
                            State = true;
                        }
                        else
                        {

                            State = false;
                        }
                    }
                }
                // if t1 is AM and t2 is PM
                if(t1.ToString("tt")=="AM" && t2.ToString("tt")=="PM")
                {
                    // t1 and t2 are in the same day
                    if(t.Ticks>=t1.Ticks && t.Ticks<=t2.Ticks)
                    {
                        State = true;
                    }
                    else
                    {
                        State = false;
                    }
                }
                // if t1 is PM and t2 is AM
                if(t1.ToString("tt")=="PM" && t2.ToString("tt")=="AM")
                {
                    // t2 is the next day
                    if(t.Ticks>=t1.Ticks && t.Ticks<=t2.AddDays(1).Ticks)
                    {
                        State = true;
                    }
                    else
                    {
                        State = false;
                    }
                }
                // if t1 and t2 are PM
                if(t1.ToString("tt")=="PM" && t2.ToString("tt")=="PM")
                {
                    // if t1 and t2 are in the same day
                    if(t1.Ticks<t2.Ticks)
                    {
                        // compare t between t1 and t2
                        if(t.Ticks>=t1.Ticks && t.Ticks<=t2.Ticks)
                        {
                            State = true;
                        }
                        else
                        {
                            State = false;
                        }
                    }
                    // if t2 is the next day
                    if(t1.Ticks>t2.Ticks)
                    {
                        // compare t between t1 and t2
                        if(t.Ticks>=t1.Ticks && t.Ticks<=t2.AddDays(1).Ticks)
                        {
                            State = true;
                        }
                        else
                        {
                            State = false;
                        }
                    }
                }
            }
            else if(t.ToString("tt")=="PM")
            {
                // if t1 and t2 are PM
                if(t1.ToString("tt")=="PM" && t2.ToString("tt")=="PM")
                {
                    // if t1 and t2 are in the same day
                    if(t1.Ticks<t2.Ticks)
                    {
                        // compare t between t1 and t2
                        if (t.Ticks >= t1.Ticks && t.Ticks <= t2.Ticks)
                        {
                            State = true;
                        }
                        else
                        {
                            State = false;
                        }
                    }
                    // if t2 is in the next day
                    else if(t1.Ticks>t2.Ticks)
                    {
                        if(t.Ticks>=t1.Ticks && t.Ticks<=t2.AddDays(1).Ticks)
                        {
                            State = true;
                        }
                        else
                        {
                            State = false;
                        }
                    }
                   
                }
                // if t1 is PM and t2 is AM
                if(t1.ToString("tt")=="PM" && t2.ToString("tt")=="AM")
                {
                    // compare t between t1 and t2
                    if (t.Ticks >= t1.Ticks && t.Ticks <= t2.AddDays(1).Ticks)
                    {
                        State = true;
                    }
                    else
                    {
                        State = false;
                    }
                }
                // if t1 is AM and t2 is PM
                if(t1.ToString("tt")=="AM" && t2.ToString("tt")=="PM")
                {
                    // compare t between t1 and t2
                    if(t.Ticks>=t1.Ticks && t.Ticks<=t2.Ticks)
                    {
                        State = true;
                    }
                    else
                    {
                        State = false;
                    }
                }
                // if t1 and t2 are am
                if(t1.ToString("tt")=="AM" && t2.ToString("tt")=="AM")
                {
                    // if t1 and t2 are in the same day
                   if(t1.Ticks<t2.Ticks)
                   {
                       // compare t between t1 and t2
                       if(t.Ticks>= t1.Ticks && t.Ticks<=t2.Ticks)
                       {
                           State = true;
                       }
                       else
                       {
                           State = false;
                       }
                   }
                   else if(t1.Ticks>t2.Ticks)
                   {
                       // compare t between t1 and t2
                       if(t.Ticks>=t1.Ticks && t.Ticks<= t2.AddDays(1).Ticks)
                       {
                           State = true;
                       }
                       else
                       {
                           State = false;
                       }
                   }
                }
            }
            MessageBox.Show(State.ToString());
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string abc = "a,b,c,";
            if(abc!="")
            {
                abc = abc.Substring(0, abc.Length - 1);
            }
            MessageBox.Show(abc);
        }
    }
}
